//
//  ECAddOrderTableViewCell.m
//  ECERP.CRM
//
//  Created by 刘思麟 on 2018/10/22.
//  Copyright © 2018年 Mac. All rights reserved.
//

#import "ECAddOrderTableViewCell.h"

@interface ECAddOrderTableViewCell()

@property (nonatomic,strong) CAShapeLayer * bottomLine;

@property (nonatomic,strong) UIImageView * indicatorImgV;

@end

@implementation ECAddOrderTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self setupUI];
        self.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return self;
}

- (void)layoutSubviews {
    [super layoutSubviews];
    if (!self.bottomLine) {
        self.bottomLine = [CAShapeLayer layer];
        self.bottomLine.borderWidth = 0.25 * PX_RELATIVE375;
        self.bottomLine.borderColor = ECCOLOR(0xf2f2f2).CGColor;
        [self.contentView.layer addSublayer:self.bottomLine];
    }
    self.bottomLine.frame = CGRectMake(12 * PX_RELATIVE375, self.contentView.height-0.5*PX_RELATIVE375, self.contentView.width - 24 * PX_RELATIVE375, 0.5 * PX_RELATIVE375);
}

- (void)prepareForReuse {
    [super prepareForReuse];
    self.imgV.image = nil;
    self.titleLB.text = nil;
    self.numLB.text = nil;
    self.specificationLB.text = nil;
    self.desLB.text = nil;
    self.priceLB.text = nil;
}

- (void)setupUI {
    __weak typeof(self) weakSelf = self;
    self.imgV = [UIImageView new];
    self.imgV.contentMode = UIViewContentModeScaleAspectFill;
    [self.contentView addSubview:self.imgV];
    [self.imgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.mas_equalTo(weakSelf.contentView).mas_offset(12 * PX_RELATIVE375);
        make.width.height.mas_equalTo(80 * PX_RELATIVE375);
    }];
    
    self.indicatorImgV = [UIImageView new];
    self.indicatorImgV.image = [UIImage imageNamed:@"editor_icon"];
    self.indicatorImgV.contentMode = UIViewContentModeScaleAspectFit;
    [self.contentView addSubview:self.indicatorImgV];
    [self.indicatorImgV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(weakSelf.contentView).mas_offset(-12 * PX_RELATIVE375);
        make.top.mas_equalTo(weakSelf.imgV);
        make.height.width.mas_equalTo(18 * PX_RELATIVE375);
    }];
    
    self.priceLB = [UILabel new];
    self.priceLB.font = ECFONT(12 * PX_RELATIVE375);
    self.priceLB.textColor = ECCOLOR(0x999999);
    [self.contentView addSubview:self.priceLB];
    [self.priceLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.indicatorImgV);
        make.right.mas_equalTo(weakSelf.indicatorImgV.mas_left).mas_offset(-10 * PX_RELATIVE375);
    }];
    
    self.titleLB = [UILabel new];
    self.titleLB.font = ECBOLDFONT(14 * PX_RELATIVE375);
    self.titleLB.textColor = ECCOLOR(0x000000);
    [self.contentView addSubview:self.titleLB];
    [self.titleLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.mas_equalTo(weakSelf.indicatorImgV);
        make.left.mas_equalTo(weakSelf.imgV.mas_right).mas_offset(12 * PX_RELATIVE375);
        make.right.mas_lessThanOrEqualTo(weakSelf.priceLB.mas_left).mas_offset(-10 * PX_RELATIVE375);
    }];
    
    self.numLB = [UILabel new];
    self.numLB.font = ECBOLDFONT(12 * PX_RELATIVE375);
    self.numLB.textColor = ECCOLOR(0x333333);
    [self.contentView addSubview:self.numLB];
    [self.numLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.imgV.mas_right).mas_offset(12 * PX_RELATIVE375);
        make.right.mas_lessThanOrEqualTo(weakSelf.contentView).mas_offset(-12 * PX_RELATIVE375);
        make.centerY.mas_equalTo(weakSelf.imgV).mas_offset(-11*PX_RELATIVE375);
    }];
    
    self.specificationLB = [UILabel new];
    self.specificationLB.font = ECBOLDFONT(12 * PX_RELATIVE375);
    self.specificationLB.textColor = ECCOLOR(0x999999);
    [self.contentView addSubview:self.specificationLB];
    [self.specificationLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.imgV.mas_right).mas_offset(12 * PX_RELATIVE375);
        make.right.mas_lessThanOrEqualTo(weakSelf.contentView).mas_offset(-12 * PX_RELATIVE375);
        make.centerY.mas_equalTo(weakSelf.imgV).mas_offset(11 * PX_RELATIVE375);
    }];
    
    self.desLB = [UILabel new];
    self.desLB.font = ECBOLDFONT(12 * PX_RELATIVE375);
    self.desLB.textColor = ECCOLOR(0x999999);
    [self.contentView addSubview:self.desLB];
    [self.desLB mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.imgV.mas_right).mas_offset(12 * PX_RELATIVE375);
        make.right.mas_lessThanOrEqualTo(weakSelf.contentView).mas_offset(-12 * PX_RELATIVE375);
        make.bottom.mas_equalTo(weakSelf.imgV);
    }];
}

@end
